package com.le.tester.imooc.ccmouse.socket;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 描述：socket server
 */
public class Server {
    public static void main(String[] args) throws IOException {
        //监听6666端口
        RequestHandler requestHandler = new RequestHandler();
        try (ServerSocket serverSocket = new ServerSocket(6666)) {
            System.out.println("listening on " + serverSocket.getLocalSocketAddress());

            //服务端接受的一定是这个客户端的socket
            while (true) {
                Socket clientSocket = serverSocket.accept();
                System.out.println("accepting incoming connection from " + clientSocket.getRemoteSocketAddress());
                ClientHandler clientHandler = new ClientHandler(clientSocket, requestHandler);
                clientHandler.run();
            }
        }
    }
}
